package com.yj.suncity.onekeyshare;

import java.io.File;
import java.io.FileOutputStream;

import com.yj.suncity.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.CompressFormat;
import cn.sharesdk.framework.PlatformActionListener;

// 使用快捷分享完成分享（请务必仔细阅读位于SDK解压目录下Docs文件夹中OnekeyShare类的JavaDoc）
	/**ShareSDK集成方法有两种</br>
	 * 1、第一种是引用方式，例如引用onekeyshare项目，onekeyshare项目再引用mainlibs库</br>
	 * 2、第二种是把onekeyshare和mainlibs集成到项目中，本例子就是用第二种方式</br>
	 * 请看“ShareSDK 使用说明文档”，SDK下载目录中 </br>
	 * 或者看网络集成文档 http://wiki.mob.com/Android_%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97
	 * 3、混淆时，把sample或者本例子的混淆代码copy过去，在proguard-project.txt文件中
	 *
	 *
	 * 平台配置信息有三种方式：
	 * 1、在我们后台配置各个微博平台的key
	 * 2、在代码中配置各个微博平台的key，http://mob.com/androidDoc/cn/sharesdk/framework/ShareSDK.html
	 * 3、在配置文件中配置，本例子里面的assets/ShareSDK.conf,
	 */
public class ShowShare {
	
	private Context context;
	private boolean silent;
	private String platform;
	private PlatformActionListener actionListener;
	

		public ShowShare(Context context,String platform,PlatformActionListener actionListener) {
		super();
		this.context = context;
		this.silent = true;
		this.platform = platform;
		this.actionListener = actionListener;
	}



		public void showShare(String title,String content,String shareUrl,String imgUrl) {
			
			final OnekeyShare oks = new OnekeyShare();

			//oks.setAddress("12345678901");
			oks.setTitle(title);
			oks.setTitleUrl(shareUrl);
			oks.setText(content);
			oks.setImageUrl(imgUrl);
            oks.setImagePath(ImagePath());
			oks.setUrl(shareUrl);
			oks.setFilePath(shareUrl);
			oks.setComment(context.getResources().getString(R.string.app_name));
			oks.setSite(context.getResources().getString(R.string.app_name));
			oks.setSiteUrl(shareUrl);
			oks.setVenueName(context.getResources().getString(R.string.app_name));
//			oks.setVenueDescription(CustomShareFieldsPage.getString("venueDescription", "This is a beautiful place!"));
//			oks.setLatitude(23.056081f);
//			oks.setLongitude(113.385708f);
			oks.setSilent(silent);
			oks.setShareFromQQAuthSupport(false);
//			String theme = CustomShareFieldsPage.getString("theme", "classic");
//			if(OnekeyShareTheme.SKYBLUE.toString().toLowerCase().equals(theme)){
//				oks.setTheme(OnekeyShareTheme.SKYBLUE);
//			}else{
				oks.setTheme(OnekeyShareTheme.CLASSIC);
//			}

			if (platform != null) {
				oks.setPlatform(platform);
			}


			// 令编辑页面显示为Dialog模式
			oks.setDialogMode();

			// 在自动授权时可以禁用SSO方式
			//if(!CustomShareFieldsPage.getBoolean("enableSSO", true))
				oks.disableSSOWhenAuthorize();

			// 去除注释，则快捷分享的操作结果将通过OneKeyShareCallback回调
			oks.setCallback(actionListener);

			// 去自定义不同平台的字段内容
			//oks.setShareContentCustomizeCallback(new ShareContentCustomizeDemo());

			// 去除注释，演示在九宫格设置自定义的图标
//			Bitmap enableLogo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
//			Bitmap disableLogo = BitmapFactory.decodeResource(getResources(), R.drawable.sharesdk_unchecked);
//			String label = getResources().getString(R.string.app_name);
//			OnClickListener listener = new OnClickListener() {
//				public void onClick(View v) {
//					String text = "Customer Logo -- ShareSDK " + ShareSDK.getSDKVersionName();
//					Toast.makeText(getContext(), text, Toast.LENGTH_SHORT).show();
//				}
//			};
//			oks.setCustomerLogo(enableLogo, disableLogo, label, listener);

			// 去除注释，则快捷分享九宫格中将隐藏新浪微博和腾讯微博
//			oks.addHiddenPlatform(SinaWeibo.NAME);
//			oks.addHiddenPlatform(TencentWeibo.NAME);

			// 为EditPage设置一个背景的View
//			oks.setEditPageBackground(getPage());
			oks.show(context);
		}
		private String ImagePath() {
			String TEST_IMAGE;
			try {
				String cachePath = cn.sharesdk.framework.utils.R.getCachePath(context, null);
				TEST_IMAGE = cachePath + "app_icon.png";
				File file = new File(TEST_IMAGE);
				if (!file.exists()) {
					file.createNewFile();
					Bitmap pic = BitmapFactory.decodeResource(context.getResources(), R.drawable.app_icon);
					FileOutputStream fos = new FileOutputStream(file);
					pic.compress(CompressFormat.JPEG, 100, fos);
					fos.flush();
					fos.close();
				}
			} catch(Throwable t) {
				t.printStackTrace();
				TEST_IMAGE = null;
			}
			return TEST_IMAGE;
		}
}
